@include('public.head')
<link href="{{ URL::asset('./admin/css/plugins/iCheck/custom.css') }}" rel="stylesheet">
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="">
        <div>
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>
                        栏目权限
                    </h5>
                </div>
                <div class="ibox-content">
                    <form method="post" action="" class="form-horizontal m-t">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">导航栏目</label>
                            <div class="col-sm-10">
                                {{-- checked="" --}}
                                @forelse ($menus as $nav)
                                <div class="checkbox i-checks">
                                    <label>
                                        <input type="checkbox" name="id" value="{{$nav->id}}" @if ($nav->is_selected == 1)checked=""@endif> <i></i> {{$nav->ch_name}}
                                    </label>
                                </div>
                                @empty
                                @endforelse
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                               <input type="hidden" name="user_id" value="{{$user_id}}">
                               <button class="btn btn-primary">保存</button>
                               <a href="javascript:void(0)" id="select" class="btn btn-primary">全选</a>
                               <a href="javascript:void(0)" id="cancle" class="btn btn-default">取消</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
    <script type="text/javascript" src="{{ URL::asset('./admin/js/plugins/iCheck/icheck.min.js') }}"></script>
    

    <script>
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });

        $(".m-t").submit(function(e){
            var id = [];
            $("input[name='id']").each(function(){
                if($(this).parent().hasClass('checked')){
                    id.push($(this).val());
                }
            });

            var form = new FormData();

            var user_id = $("input[name='user_id']").val();

            form.append("id", id);
            form.append("user_id", user_id);

            $.ajax({
                url:"/add_menu_user",    //请求的url地址
                dataType:"json",   //返回格式为json
                data:form,    //参数值
                processData: false,
                contentType: false,   
                type:"POST",   //请求方式
                success:function(req){
                    //请求成功时处理
                    if(req.status == 0){
                        layer.msg(req.message);
                        return false;
                    }
                       
                    layer.msg('操作成功！');
                    // setTimeout(function(){
                    //      window.location.href = "/user";
                    // },1000);
                }
            });

            return false;
        });

        $("#select").click(function(){
            $('.icheckbox_square-green').addClass('checked');
        });

        $("#cancle").click(function(){
            $('.icheckbox_square-green').removeClass('checked');
        });
    </script>

</body>
</html>